/**
 *
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 *
 *
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 *
 * */
package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TUser;

/**
 * 说明：会员卡查询Model
 *
 * @Author：李智深
 * @Date：2012-03-14
 */
public class MemberQueryCardModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
//	private Vector<List<Object>> rowdatas = new Vector<List<Object>>();
	private List<TUser> tUserList=new Vector<TUser>();
	private Vector<String> columns = new Vector<String>();

	private boolean[] bools;

	public MemberQueryCardModel() {
		columns.add("编号");
		columns.add("卡号");
		columns.add("用户名");
		columns.add("姓名");
		columns.add("手机号");
		columns.add("发卡时间");
		columns.add("余额");
		columns.add("积分");
		columns.add("消费次数");
		columns.add("最后登录时间");
		// columns.add("操作");
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		switch(columnIndex) {
		case 6:
		case 7:
			return Double.class;
	}
		return super.getColumnClass(columnIndex);
	}

	//获得行数
	public int getRowCount(){
		return tUserList.size();
	}

	//获得列数
	public int getColumnCount(){
		return columns.size();
	}

	//获得单元格的值
	public Object getValueAt(int row,int column){
//		if (row >= tCommodityList.size())
//			return null;
		TUser tUser = tUserList.get(row);
		return gettCommodityValueByCol(tUser, row, column+1);
	}

	public Object gettCommodityValueByCol(TUser tUser, int row, int column) {
		switch (column) {
			case 0:
				return tUser.getUserID();

			case 1:
				return bools[row];
			case 2:
				return tUser.getCardNum();
			case 3:
				return tUser.getUserName();
			case 4:
				return tUser.getRealName();
			case 5:
				return tUser.getMobile();
			case 6:
				return tUser.getCreateTime();
			case 7:
				return tUser.getMoney();
			case 8:
				return tUser.getPoint();
			case 9:
				return tUser.getBuyCount();
			case 10:
				return tUser.getLastLoginTime();
		}
		return null;
	}

	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}

	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		if (columnIndex == 0 || columnIndex == 4)
			return true;
		return false;
	}

	public void removeData(int row){
		tUserList.remove(row);
	}

	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		TUser tUser = tUserList.get(rowIndex);
		switch (columnIndex) {
			case 0:
				bools[rowIndex] = (Boolean)aValue;
				return;
		}
		super.setValueAt(aValue, rowIndex, columnIndex);
	}

	public List<TUser> getTCommodityList() {
		return tUserList;
	}

	public boolean[] getBools() {
		return bools;
	}
	public void setRowData(List<TUser> tUserList) {
		this.tUserList = tUserList;
		for (int i = tUserList.size() - 1; i >= 0; --i) {
		}
		bools = new boolean[tUserList.size()];
	}

	public void clear(){
		tUserList.clear();
	}
}
